package com.sc.nft.admin.controller;


import com.sc.nft.annotation.DistributedLock;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.constant.DistributedLockConstant;
import com.sc.nft.entity.dto.SupplierManageBindingEditDTO;
import com.sc.nft.entity.dto.SupplierManageBindingSaveDTO;
import com.sc.nft.entity.dto.SupplierManageMallBindingDTO;
import com.sc.nft.service.SupplierManageBindingService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 供应商和商品绑定(SupplierManageBindingBinding)表控制层
 *
 * @author 王伟成
 * @since 2023-10-17 15:55:39
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/supplierManageBindingBinding")
@Api(tags = "商品绑定供应商")
@Valid
public class SupplierManageBindingController {
    /**
     * 服务对象
     */
    private final SupplierManageBindingService supplierManageBindingService;

    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "供应商绑商品", notes = "供应商绑商品", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result save(@RequestBody SupplierManageBindingSaveDTO supplierManageBindingSaveDTO) {
        supplierManageBindingService.save(supplierManageBindingSaveDTO);
        return Result.success();
    }

    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "编辑", notes = "编辑", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    @DistributedLock(value = {"supplierManageBindingBinding","#{supplierManageBindingEditDTO.mallId}"},pattern = DistributedLockConstant.TRY_LOCK,message = "勿频繁操作")
    public Result edit(@RequestBody SupplierManageBindingEditDTO supplierManageBindingEditDTO) {
        supplierManageBindingService.edit(supplierManageBindingEditDTO);
        return Result.success();
    }


    @PostMapping(value = "/mallBinding", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "商品绑定", notes = "商品绑定", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result mallBinding(@RequestBody SupplierManageMallBindingDTO supplierManageMallBindingDTO) {
        supplierManageBindingService.mallBinding(supplierManageMallBindingDTO);
        return Result.success();
    }
}
